package com.demo.reservation;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.TemplateConfig;
import com.baomidou.mybatisplus.generator.config.TemplateType;
import com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder;
import com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import org.junit.jupiter.api.Test;

import java.util.Collections;

public class GenCode {
    @Test
    void testCreate() {
        final TemplateConfig build = new TemplateConfig.Builder().disable().build();
        FastAutoGenerator
                .create("jdbc:mysql://localhost:3306/test", "root", "123456")
                .globalConfig(builder -> {
                    builder.author("yaclty") // 设置作者
                            .enableSwagger() // 开启 swagger 模式
                            .fileOverride() // 覆盖已生成文件
                            .outputDir("D:/cd"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.demo") // 设置父包名
                            .moduleName("reservation") // 设置父包模块名
                            .pathInfo(Collections.singletonMap(OutputFile.mapperXml, "D:/cd/mapper")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder
//                            .enableSkipView()
                            .addInclude("pet_pet_info","pet_userinfo","pet_reservation") // 设置需要生成的表名
//                            .addTablePrefix("pet_")   // 设置过滤表前缀
                            .entityBuilder().enableLombok();
                })
//                .templateConfig(conf -> {
//                    conf.disable();
//                    conf.disable(TemplateType.ENTITY);
//                })
                .templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }
}
